/*
 * @Author: HeAo
 * @Date: 2021-11-01 11:39:54
 * @LastEditTime: 2021-11-01 11:51:03
 * @LastEditors: HeAo
 * @Description:
 * @FilePath: \web2103-2105\web2103code\4-1-Nodejs\day02\3-event.js
 * 别乱动！
 */
let EventEmmiter = require('events')

// 生成一个新的类
class MyEmmiter extends EventEmmiter {

}

// 声明实例
const emmiter = new MyEmmiter()

// 定义事件类型，并做绑定
emmiter.on('touch', () => {
  console.log('不要摸我');
})
let handler = () => {
  console.log('点击我');
}
emmiter.on('click', handler)

// 事件解绑
emmiter.off('click', handler)

// 触发事件
emmiter.emit('touch');

console.log(emmiter.eventNames());
console.log(emmiter.listeners('touch'));
